package com.xteam.youin_supplier.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xteam.youin_supplier.R;


/**
 * Created by Curry on 2015-12-16.
 */
public class MessageListViewAdapter extends RecyclerView.Adapter<MessageListViewAdapter.ViewHolder> implements View.OnClickListener {

    private Context mContext;
    public MessageListViewAdapter(Context context) {
        mContext = context;
    }
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    @Override
    public void onClick(View view) {
        if (mOnItemClickListener != null) {
            //注意这里使用getTag方法获取数据
            mOnItemClickListener.onItemClick(view,(int)view.getTag());
        }
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    //define interface
    public static interface OnRecyclerViewItemClickListener {
        void onItemClick(View view, int position);
    }

    @Override
    public MessageListViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.message_list_title_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        //将创建的View注册点击事件
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MessageListViewAdapter.ViewHolder holder, int position) {
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return 10;
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        private TextView infoDetail;
        public ViewHolder(View itemView) {
            super(itemView);
            infoDetail = (TextView) itemView.findViewById(R.id.info_detail);
        }

        public TextView getInfoDetail() {
            return infoDetail;
        }

        public void setInfoDetail(TextView infoDetail) {
            this.infoDetail = infoDetail;
        }
    }
}
